package com.ball.snake;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

import java.security.PublicKey;

/**
 * Created by Administrator on 2018/9/17 0017.
 */

public class Block {
    private int x;
    private int y;
    private int dir;
    public static final int LEFT=0;
    public static final int RIGHT=1;
    public static final int UP=2;
    public static final int DOWN=3;
    public static final int WIDTH=10;
    public static int speed=10;
    public int color=Color.GRAY;

    public int getColor() {
        return color;
    }

    public void setColor(int color) {
        this.color = color;
    }

    public Block(int x, int y, int dir){
        this.x=x;
        this.y=y;
        this.dir=dir;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getDir() {
        return dir;
    }

    public void setDir(int dir) {
        this.dir = dir;
    }

    public static int getLEFT() {
        return LEFT;
    }

    public static int getRIGHT() {
        return RIGHT;
    }

    public static int getUP() {
        return UP;
    }

    public static int getDOWN() {
        return DOWN;
    }

    public static int getWIDTH() {
        return WIDTH;
    }

    public void logic(){
        switch (dir){
            case LEFT:
                x-=speed;
                break;
            case RIGHT:
                x+=speed;
                break;
            case UP:
                y-=speed;
                break;
            case DOWN:
                y+=speed;
                break;
        }
    }

    public void draw(Canvas canvas, Paint paint){
        paint.setColor(color);
        paint.setAlpha(150);
        canvas.drawRect(x,y,x+WIDTH,y+WIDTH,paint);
    }
}
